package com.example.wan1.view.coin;

import com.example.wan1.data.BaseObserver;
import com.example.wan1.data.RetrofitUtil;
import com.example.wan1.data.RxSchedulers;
import com.example.wan1.model.CoinBean;
import com.example.wan1.model.CoinSignInBean;
import com.example.wan1.model.common.CommonResList;

import javax.inject.Inject;

/***
 * 创建时间：2020/7/28 18:37
 * 创建人：10850
 * 功能描述：
 */
public class CoinPresenter implements CoinContract.Presenter {

    @Inject
    CoinContract.View mView;

    @Inject
    public CoinPresenter() {
    }

    @Override
    public void getCoinSignInData(int page) {
        RetrofitUtil.getInstance().getCoinSignInList(page)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<CoinSignInBean>>() {
                    @Override
                    public void onSuccess(CommonResList<CoinSignInBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    @Override
    public void getRankList(int page) {
        RetrofitUtil.getInstance().getCoinRankList(page)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<CoinBean>>() {
                    @Override
                    public void onSuccess(CommonResList<CoinBean> result) {
                        mView.onRank(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }
}
